//
//  tool.m
//  HiCar
//
//  Created by 丁一 on 2019/2/11.
//  Copyright © 2019 丁一. All rights reserved.
//

#import "tool.h"
#import <Foundation/Foundation.h>

@implementation tool

//自然排序
+ (NSString *)parameterMakerOrderTostring:(NSDictionary*)parameter{
    
    NSArray *keyArray = [parameter allKeys];
    NSArray *orderArray = [keyArray sortedArrayUsingSelector:@selector(compare:)];
    NSMutableArray  *resultArray = [NSMutableArray array];
    
    [orderArray enumerateObjectsUsingBlock:^(NSString  *key, NSUInteger idx, BOOL * _Nonnull stop) {
        
        NSString *value = parameter[key];
        NSString *result = [NSString stringWithFormat:@"%@=%@",key,value];
        [resultArray addObject:result];
        
    }];
    
    NSString *parameterString = [resultArray componentsJoinedByString:@"&"];
    return  parameterString;
}
//编码
+ (NSString *)encodeToPercentEscapeString:(NSString *)input {
    NSString *outputStr = (NSString *)
    CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                              (CFStringRef) input,
                                                              NULL,
                                                              (CFStringRef) @"!'();:@&=+$,/?%#[]",
                                                              kCFStringEncodingUTF8));
    //!*'();:@&=+$,/?%#[]
    return outputStr;
}

@end
